package eerbaar.shared.internal.tree.commands;

import eerbaar.shared.tree.INode;
import eerbaar.shared.tree.IPayload;

public class FindChildCmd {

    private final INode start;

    public FindChildCmd(INode start) {
        this.start = start;
    }

    public INode execute(String name) {
        assert (this.start != null);
        assert (name != null);

        INode result = null;

        INode[] children = this.start.getChildren();
        for (INode node : children) {

            IPayload payload = node.getPayload();
            String test = payload.getKey();
            if (test.equals(name)) {
                result = node;
                break;
            }
        }

        return result;
    }

}
